<template>
  <!-- 订单详情页 -->
  <div>
    <FilterTable
      ref="table"
      height="auto"
      maxHeight="350"
      :columns="tableColumns"
      :dataSource="partList"
      :isSelectColumn="false"
      :isMemoryPagination="true"
      columnsRef="partPartPurchasePurchaseOrderOrderDetail"
      :onColumnsChange="columns => (this.tableColumns = columns)"
      :onSyncTableData="handleTableDataChange"
    >
      <!-- <template slot="controls">
        <el-button size="small" type="primary">导出</el-button>
        <el-button size="small" type="danger">打印</el-button>
      </template>-->
    </FilterTable>
    <div class="bottomBtnWrap">
      <!-- <el-button @click="handleClose">取 消</el-button> -->
      <el-button type="primary" @click="handleClose">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { queryOrderPartDetailByOrderNo } from '@/api/part/partPurchase/purchaseOrder';
import { queryTex } from '@/api/part/common';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
import { arrayObjDeWeight } from '@/utils/index';

export default {
  props: {
    orderId: String
  },
  data() {
    return {
      tableColumns: this.createTableColumns(),
      fetchapi: queryOrderPartDetailByOrderNo,
      partList: [],
      tax: 0
    };
  },
  mounted() {
    this.queryDetailList();
    this.getDealerUser();
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '配件代码',
          dataIndex: 'partNo',
          width: 150,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '底盘号',
          dataIndex: 'vVin',
          width: 150,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '厂家配件代码',
          dataIndex: 'a3',
          filter: true,
          filterType: 'input'
        },
        {
          title: '含税采购单价',
          dataIndex: 'planPrice',
          precision: 2,
          filter: true,
          filterType: 'number'
        },
        {
          title: '不含税采购单价',
          dataIndex: 'nPriceNoTax',
          precision: 2,
          filter: true,
          filterType: 'number'
        },
        {
          title: '仅辖区发货',
          dataIndex: 'shipMark',
          filter: true,
          filterType: 'input'
        },
        {
          title: '订货数量',
          dataIndex: 'nOrderQty',
          filter: true,
          filterType: 'number'
        },
        {
          title: '建议数量',
          dataIndex: 'nSuggestQty',
          filter: true,
          filterType: 'number'
        },
        {
          title: '欠料数量',
          dataIndex: 'a9',
          filter: true,
          filterType: 'number'
        },
        {
          title: '需求日期',
          dataIndex: 'dDemand',
          dateFormat: 'yyyy-MM-dd',
          width: 150,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '含税采购金额',
          dataIndex: 'total_planPrice',
          precision: 2,
          filter: true,
          filterType: 'number',
          summation: true
        },
        {
          title: '不含税采购金额',
          dataIndex: 'total_nPriceNoTax',
          precision: 2,
          filter: true,
          filterType: 'number',
          summation: true
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          width: 150,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '主组号',
          dataIndex: 'a14',
          filter: true,
          filterType: 'input'
        },
        {
          title: '原始订单号',
          dataIndex: 'vOldBillNo',
          filter: true,
          filterType: 'input'
        },
        {
          title: '分店订货数量',
          dataIndex: 'nSubOrderQty',
          filter: true,
          filterType: 'number'
        },
        {
          title: '到货数量',
          dataIndex: 'nArrivalQty',
          filter: true,
          filterType: 'number'
        },
        {
          title: '操作员',
          dataIndex: 'a18',
          filter: true,
          filterType: 'input',
          filterItems: [],
          dictItems: []
        },
        {
          title: 'ETKA',
          dataIndex: 'a19',
          filter: true,
          filterType: 'input'
        },
        {
          title: '委托书编号',
          dataIndex: 'a20',
          filter: true,
          filterType: 'input'
        },
        {
          title: '送修日期',
          dataIndex: 'dEnter',
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '厂家处理说明',
          dataIndex: 'vSuhandleDesc',
          filter: true,
          filterType: 'input'
        },
        {
          title: 'R3三包采购',
          dataIndex: 'a23',
          filter: true,
          filterType: 'input'
        }
      ];
    },
    // 获取人员数据接口
    async getDealerUser() {
      const res = await getDealerUser();
      let data = arrayObjDeWeight(res.data, 'userId');
      let userList = data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
      console.log('userList', userList);
      this.tableColumns.find(item => item.dataIndex === 'a18').dictItems = userList;
    },
    // 根据订单id订单配件详情
    async queryDetailList() {
      this.$refs.table.START_LOADING();
      let res = await queryOrderPartDetailByOrderNo({
        orderNo: this.orderId
      });
      if ((res.resultCode = 200)) {
        this.partList = res.data;
      }
      this.$refs.table.STOP_LOADING();
    },
    // 弹窗关闭事件
    handleClose() {
      this.$emit('close');
    },
    // table数据变化
    handleTableDataChange(e) {
      // if (!this.tax) {
      //   let res = await queryTex();
      //   if (res.resultCode == 200) {
      //     this.tax = res.data;
      //   } else {
      //     this.tax = 0.13;
      //   }
      // }
      e.map(item => {
        // item.planPrice = item.nPriceNoTax * (1 + Number(this.tax));
        item.planPrice = item.nPurPrice || 0;
        item.total_planPrice = item.planPrice * item.nOrderQty;
        item.total_nPriceNoTax = item.nPriceNoTax * item.nOrderQty;
      });
    }
  }
};
</script>

<style scoped>
.bottomBtnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
